import {createStore} from './redux';
let addbtn = document.getElementById('addbtn');
let minusbtn = document.getElementById('minusbtn');
let root = document.getElementById('cvalue');
let initialState = 0;
function reducer(state = initialState,action){
  switch(action.type){
    case 'ADD':
      return state + 1;
    case 'MINUS':
      return state - 1;
    default: 
      return state;
  }
}
let store = createStore(reducer);

function render(){
  root.innerHTML = store.getState();
}
store.subscribe(render);
addbtn.addEventListener('click',()=>{
  store.dispatch({type: 'ADD'})
})
minusbtn.addEventListener('click',()=>{
  store.dispatch({type: 'MINUS'})
})